<?php

require_once 'App/AlbumService.php';

class App_Forms_AlbumSelector extends Zend_Form
{
	protected $albumService;
	protected $session;
	
	public function __construct()
	{
		$session = new Zend_Session_Namespace('default');
		
		$this->albumService = new App_AlbumService();
		
		if(isset($session->userID))
		{
			$this->setAttribs(array(
				'name' => 'imageForm',
				'method' => 'post',
				'enctype' => 'multipart/form-data',
				'action' => 'add',
				'accept-charset' => 'UTF-8'
			));
		
			$allAlbums = $this->albumService->getAllAlbumsByUserID($session->userID);
			$dropDown = new Zend_Form_Element_Select('myAlbum');
			$dropDown->setAttrib('id', 'albumSelector');
			
			foreach($allAlbums as $a)
			{
				$dropDown->addMultiOption($a->AlbumID, $a->Name);
			}
			
			$files = new Zend_Form_Element_File('imgFile');
			$files->setDestination('..\user_data');
			$files->setMaxFileSize(5*1024000);	//5 MBs
			
			$submit = new Zend_Form_Element_Submit('Upload');
			$this->setAction('image/add');
			$this->addElements(array(
				$dropDown,
				$files,
				$submit
			));
			
			$this->setDecorators(array(
				'FormElements',
				array('HtmlTag', array('tag' => 'dl')),
				'Form'
			));
		}
	}
}